package pl.edu.pb.wi.cookbook.entity;

import java.io.Serializable;

import javax.persistence.Id;

import pl.edu.pb.wi.cookbook.util.FullTextSearchUtil;

import com.googlecode.objectify.Key;

public class Cookbook extends FullTextSearch implements Serializable {
    private static final long serialVersionUID = -2028003991490522589L;

    @Id
    private Long id;
    private Key<User> author;
    private String name;
    private String description;
    private Boolean isPrivate;

    public Cookbook() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Key<User> getAuthor() {
        return author;
    }

    public void setAuthor(Key<User> author) {
        this.author = author;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Boolean isPrivate() {
        return isPrivate;
    }

    public Boolean getIsPrivate() {
        return isPrivate;
    }

    public void setPrivate(boolean isPrivate) {
        this.isPrivate = isPrivate;
    }

    @Override
    public void updateFts() {
        StringBuilder sb = new StringBuilder("");

        if (!isPrivate)
            sb = sb.append(name).append(" ").append(description);

        fts = FullTextSearchUtil.getTokensForIndexingOrQuery(sb.toString(),
                FullTextSearchUtil.MAXIMUM_NUMBER_OF_WORDS_TO_PUT_IN_INDEX);
    }

}
